﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;

using CNotebook;

namespace NotebookS2
{
    public partial class FND_WHOUSE : RibbonForm
    {
        public FND_WHOUSE()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string ActiveUserID { get; set; }

        public string WarehouseCode { get; set; }
        public string WarehouseName { get; set; }

        private void txtBPCode_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            WarehouseManager oManager = new WarehouseManager();
            DataTable dt = new DataTable();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            if (cboSearch.SelectedIndex == 0)
            {

                dt = oManager.GetWarehouseByCode(txtSearch.Text);

            }
            else
            {
                dt = oManager.GetWarehouseByDescription(txtSearch.Text);
            }
            oManager.Close();
            gridControl1.DataSource = dt;
            gridControl1.Refresh();

        }

        private void FND_WHOUSE_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 1;
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iFocusHandle = gridView1.FocusedRowHandle;

            if (gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["Code"]) != null)
            {
                this.WarehouseCode = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["Code"]).ToString();
                this.WarehouseName = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["Dscription"]).ToString();
            }
            else
            {
                this.WarehouseCode = "";
                this.WarehouseName = "";
            }

            this.Close();
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }
    }
}
